from boot import Union, Dict, List


__all__ = ["amount_format", "dict_list_rename_key"]


def amount_format(money: str):
    # 反转字符串
    reversed_str = money[::-1]
    # 每三位插入一个逗号
    chunks = [reversed_str[i:i + 3] for i in range(0, len(reversed_str), 3)]
    # 重新组合并反转回原来的顺序
    formatted_money = ','.join(chunks)[::-1]
    return formatted_money


def dict_list_rename_key(
        src_list: List[Dict[str, Union[str, int]]],
        old_key: List[str],
        new_key: List[str]
) -> List[Dict[str, Union[str, int]]]:
    for src_dict in src_list:
        for old, new in zip(old_key, new_key):
            src_dict[new] = src_dict.pop(old)
    return src_list